<template>
  <dialog-editor :width="80" ref="dialog" :colFlagFunc="true"></dialog-editor>
</template>

<script>


import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        purchaseProductId:{
          hidden: true
        },
        supplierId: {
          label: '询价供应商',
          list: [],
          type: 'list',
          placeholder: '请选择供应商'
        },
        supplierProductNo: {
          label: '供应商产品编号'
        },
        purchaseNumber: {
          label: '采购数量'
        },
        /*      contactOrderId: {label: '业务合同'},
              orderDetailId: {label: '业务订单'},
              clientContractNo: {label: '客户合同编号'},
              productId: {label: '产品名称'},
              orderUnitPrice: {label: '订单价格'},
              customerRequire: {label: '客户需求'},
              clientModelAmount: {label: '客户开模费用'},
              clientProofingAmount: {label: '客户打样费用'},
              clientTotalAmount: {label: '客户订单总价'},*/
        supplierUnitPrice: {label: '供应商单价', type: 'number', selectCallback: this.numberChanged},
        supplierModelAmount: {label: '供应商模具费用', type: 'number',selectCallback: this.numberChanged},
        supplierProofingAmount: {label: '供应商打样费用', type: 'number',selectCallback: this.numberChanged},
        qualityGrade: {
          label: '质量等级',
          type: 'radio',
          radioList: [
            {label: 'A', text: 'A'},
            {label: 'B', text: 'B'},
            {label: 'C', text: 'C'}
          ],
          default: 'A'
        },
        supplierTotalAmount: {label: '供应商总价格', type: 'number'},
        taxInclusive: {
          label: '含税价',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {label: 0, text: '不含税'},
            {label: 1, text: '含税'}
          ],
          default: 0
        },
        deliveryDays: {label: '交期（天）'},

        onlineTime: {label: '预计上线时间', type: 'date'},
        transportWay: {
          label: '运输方式',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {label: 0, text: '供方承担(含运费)'},
            {label: 1, text: '需方自提（不含运费）'}
          ],
          default: 0
        },
        recommendDesc: {label: '推荐理由'},
        paymentCycle: {
          label: '供应商付款周期',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {label: 0, text: '月结'},
            {label: 1, text: '款到发货'},
            {label: 2, text: '3个月账期'},
            {label: 4, text: '2个月账期'},
            {label: 3, text: '付30%定金，余款70%款到发货'}
          ],
          default: 0
        },
        remark: {label: '备注'},
//purchaseProductId
        status: {
          label: '状态', type: 'radio',
          radioBorder: false,
          radioList: [
            {label: 0, text: '询价完成'},
            {label: 1, text: '财务审核不通过'},
            {label: 2, text: '财务审核通过'}
          ],
          changedCallback: this.statusCallback,
          default: 0
        },
        recommendSupplierId: {
          label: '确认供应商',
          type: 'list',
          list: [],
          reply: () => this.dataForm.id && this.dataForm.status == 2
        },
        financeApproveTime: {label: '财务审核时间', type: 'date', reply: () => this.dataForm.id},
        financeApproveDesc: {label: '财务建议', reply: () => this.dataForm.id},
        annexFile: {
          label: '附件',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        }
      },
      dataRule: {
        /*  supplierId: [
            {required: true, message: '供应商不能为空', trigger: 'blur'}
          ],
          supplierName: [
            {required: true, message: '供应商名称不能为空', trigger: 'blur'}
          ],
          contactOrderId: [
            {required: true, message: '业务合同不能为空', trigger: 'blur'}
          ],
          orderDetailId: [
            {required: true, message: '业务订单不能为空', trigger: 'blur'}
          ],
          clientContractNo: [
            {required: true, message: '客户合同编号不能为空', trigger: 'blur'}
          ],
          productId: [
            {required: true, message: '产品名称不能为空', trigger: 'blur'}
          ],
          productNo: [
            {required: true, message: '产品名称1不能为空', trigger: 'blur'}
          ],
          orderUnitPrice: [
            {required: true, message: '订单价格不能为空', trigger: 'blur'}
          ],
          customerRequire: [
            {required: true, message: '客户需求不能为空', trigger: 'blur'}
          ],
          clientModelAmount: [
            {required: true, message: '客户开模费用不能为空', trigger: 'blur'}
          ],
          clientProofingAmount: [
            {required: true, message: '客户打样费用不能为空', trigger: 'blur'}
          ],
          clientTotalAmount: [
            {required: true, message: '客户订单总价不能为空', trigger: 'blur'}
          ],
          clientCurrencyType: [
            {required: true, message: '币种不能为空', trigger: 'blur'}
          ],
          supplierUnitPrice: [
            {required: true, message: '供应商单价不能为空', trigger: 'blur'}
          ],
          supplierModelAmount: [
            {required: true, message: '供应商模具费用不能为空', trigger: 'blur'}
          ],
          supplierProofingAmount: [
            {required: true, message: '供应商打样费用不能为空', trigger: 'blur'}
          ],
          supplierTotalAmount: [
            {required: true, message: '供应商总价格不能为空', trigger: 'blur'}
          ],
          deliveryDays: [
            {required: true, message: '交期不能为空', trigger: 'blur'}
          ],
          onlineTime: [
            {required: true, message: '上线时间不能为空', trigger: 'blur'}
          ],
          taxInclusive: [
            {required: true, message: '是否含税不能为空', trigger: 'blur'}
          ],
          transportWay: [
            {required: true, message: '是否含运不能为空', trigger: 'blur'}
          ],
          paymentCycle: [
            {required: true, message: '供应商付款周期不能为空', trigger: 'blur'}
          ],
          remark: [
            {required: true, message: '备注不能为空', trigger: 'blur'}
          ],
          recommendSupplierId: [
            {required: true, message: '推荐供应商不能为空', trigger: 'blur'}
          ],
          recommendDesc: [
            {required: true, message: '推荐理由不能为空', trigger: 'blur'}
          ],
          status: [
            {required: true, message: '状态不能为空', trigger: 'blur'}
          ],
          createUser: [
            {required: true, message: '不能为空', trigger: 'blur'}
          ],
          createTime: [
            {required: true, message: '不能为空', trigger: 'blur'}
          ],
          updateUser: [
            {required: true, message: '不能为空', trigger: 'blur'}
          ],
          updateTime: [
            {required: true, message: '不能为空', trigger: 'blur'}
          ],
          financeApproveTime: [
            {required: true, message: '财务审核时间不能为空', trigger: 'blur'}
          ],
          financeApproveDesc: [
            {required: true, message: '财务建议不能为空', trigger: 'blur'}
          ],
          financeApproveStatus: [
            {required: true, message: '财务审核状态不能为空', trigger: 'blur'}
          ],
          financeUser: [
            {required: true, message: '财务审核人员不能为空', trigger: 'blur'}
          ],
          annexFile: [
            {required: true, message: '附件不能为空', trigger: 'blur'}
          ]*/
      }
    }
  },
  methods: {
    numberChanged() {
      const supplierUnitPrice = this.R.propOr(0, 'supplierUnitPrice', this.dataForm)
      const purchaseNumber = this.R.propOr(0, 'purchaseNumber', this.dataForm)
      const supplierModelAmount = this.R.propOr(0, 'supplierModelAmount', this.dataForm)
      const supplierProofingAmount = this.R.propOr(0, 'supplierProofingAmount', this.dataForm)

      this.dataForm.supplierTotalAmount = supplierUnitPrice * purchaseNumber + supplierModelAmount+supplierProofingAmount
    },
    statusCallback(value) {
      if (value == 2  ) {
        this.dataForm.recommendSupplierId = this.dataForm.supplierId
      }else {
        this.dataForm.recommendSupplierId = null
      }
    },

    init(id, property) {
      this.initSupplierList()
      this.initSupplierList('recommendSupplierId')
      this.dataForm.id = id || 0
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule(),
        initApi: 'purchaseApi/getPurchaseInquiryInfoManageInfo',
        saveApi: 'purchaseApi/savePurchaseInquiryInfoManage',
        updateApi: 'purchaseApi/updatePurchaseInquiryInfoManage',
        objectName: 'purchaseInquiryInfoManage'
      }),
        this.$nextTick(() => {
          if (!this.R.isNil(property)) {
            Object.keys(property).forEach((key) => {
              this.dataForm[key] = property[key]
            })
          }
        })

    }
  }
}
</script>
